package com.zhl.study.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhl.study.model.OssFile;
import com.zhl.study.base.ResponseFactory;
import com.zhl.study.base.Result;
import com.zhl.study.service.OssTemplate;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zl0422@lingzifu.cn
 * @version v1.0
 * @description minIo文件服务控制器
 * @date 2024/5/11-16:49
 */

@Slf4j
@RestController
@RequestMapping("/minio")
public class MinIoController {

    @Autowired
    OssTemplate oss;

    @PostMapping("/photo")
    @ApiOperation(httpMethod = "POST", value = "上传文件")
    public Result<Object> analysisPhoto(@RequestParam("folderName") String folderName,
                                            @RequestParam("fileName") String fileName,
                                            @RequestParam("file") MultipartFile file){
        OssFile ossFile = oss.upLoadFile(folderName, fileName, file);
        log.info(JSONObject.toJSONString(ossFile));
        return ResponseFactory.ok(ossFile);
    }
}
